package com.stt.base.controller;

import com.stt.base.model.TaskSaveVO;
import com.stt.base.service.BadTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/api/task/v1")
public class BadTaskController {

    @Autowired
    private BadTaskService badTaskService;

    // 添加任务
    @PostMapping
    public String addTask(@RequestBody TaskSaveVO taskSaveVO) throws InterruptedException {
//        for (int i = 0; i < 1000; i++) {
//            new Thread(() -> {
//                badTaskService.addTask(taskSaveVO);
//            }).start();
//        }
        badTaskService.addTask(taskSaveVO);
        TimeUnit.SECONDS.sleep(30);
        System.out.println("最终任务数量：" + badTaskService.getTaskNumber());
        return "添加成功";
    }

    // 遍历任务列表
    @GetMapping("/list/{priority}")
    public String listTask(@PathVariable("priority") int priority) {
        badTaskService.listTasks(priority);
        return "遍历成功";
    }
}
